@page
@{ Layout = "_LayoutHome"; }
@section Styles{
  <style>
    body {
      background: #f5f5f5;
    }
    .wrapper-page {
      margin: 4% auto;
      max-width: 460px;
    }
    a {
      color: rgb(51, 193, 177);
      text-decoration: none;
    }
  </style>
}

<div class="wrapper-page">
  <el-card class="box-card">
    <div slot="header" class="clearfix">
      <span>用户注册</span>
    </div>

    <el-form v-on:submit.native.prevent ref="form" :model="form" size="medium" label-width="100px" status-icon>
      <el-form-item label="用户名" prop="userName" :rules="[{ required: true, message: '请输入用户名' }]">
        <el-input v-model="form.userName"></el-input>
        <small class="tips">用户名是用户的唯一标识，注册后无法更改</small>
      </el-form-item>

      <el-form-item v-if="isMobile" label="手机号码" prop="mobile" :rules="[
          { required: true, message: '请输入手机号码' },
          { validator: utils.validateMobile, message: '请输入有效的手机号码' }
        ]">
        <el-input v-model="form.mobile" placeholder="请输入手机号码"></el-input>
        <small class="tips">手机号码可用于登录、找回密码等功能</small>
      </el-form-item>
      <el-form-item v-if="isMobileCode" label="短信验证码" prop="code" :rules="[{ required: true, message: '请输入短信验证码' }]">
        <el-input v-model="form.code" autocomplete="off" placeholder="请输入短信验证码">
          <template slot="append">
            <el-link :underline="false" v-on:click.prevent="btnSendSmsClick">
              {{ countdown > 0 ? countdown + '秒': '获取验证码' }}
            </el-link>
          </template>
        </el-input>
      </el-form-item>

      <el-form-item v-if="isUserRegistrationEmail" label="电子邮箱" prop="email" :rules="[
        { required: true, message: '请输入电子邮箱' },
        { type: 'email', message: '请输入有效的电子邮箱' }
      ]">
        <el-input v-model="form.email" placeholder="请输入电子邮箱"></el-input>
        <small class="tips">电子邮箱可用于登录、找回密码等功能</small>
      </el-form-item>

      <el-form-item label="密码" prop="password" :rules="[{ required: true, message: '请输入密码' }]">
        <el-input v-model="form.password" type="password" name="password" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item label="确认密码" prop="confirmPassword" :rules="[{ required: true, message: '请输入确认密码' }, { validator: validatePass }]">
        <el-input v-model="form.confirmPassword" type="password" name="confirmPassword" autocomplete="off"></el-input>
      </el-form-item>
      <el-form-item v-if="isUserRegistrationGroup" label="用户组" prop="groupId" :rules="[{ required: true, message: '请选择用户组' }]">
        <el-select v-model="form.groupId" placeholder="请选择">
          <el-option
            v-for="group in groups"
            :key="group.id"
            :label="group.groupName"
            :value="group.id"></el-option>
        </el-select>
      </el-form-item>

      @await Html.PartialAsync("_PartialForm")

      <el-form-item v-if="!isMobileCode && !isUserCaptchaDisabled" label="验证码" prop="captchaValue" :rules="[{ required: true, message: '请输入验证码' }]">
        <el-input v-model="form.captchaValue" placeholder="请输入验证码"></el-input>
        <div style="margin-top: 5px;">
          <a href="javascript:;" v-on:click="apiCaptchaReload">
            <img v-show="captchaUrl" style="display: none" class="float-right rounded" :src="captchaUrl" align="absmiddle">
          </a>
        </div>
      </el-form-item>
      <el-divider></el-divider>
      <div style="height: 10px"></div>
      <el-form-item>
        <div v-if="isHomeAgreement">
          <el-checkbox v-model="isAgreement" style="margin-right: 10px; margin-bottom: 5px;">
            <span v-html="homeAgreementHtml"></span>
          </el-checkbox>
        </div>
        <el-button type="primary" :disabled="isHomeAgreement && !isAgreement" v-on:click="btnRegisterClick">注册</el-button>
        <el-link :href="utils.getRootUrl('login')" icon="el-icon-user" type="primary" :underline="false" style="margin-left: 10px">已有账号，请登录</el-link>
      </el-form-item>

    </el-form>

  </el-card>
</div>

@section Scripts{
  <script src="/sitefiles/assets/js/home/register.js" type="text/javascript"></script>
}